package com.chen.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chen.entity.ExamChoose;
import com.chen.vo.ExamChooseVO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 考试选择记录信息Mapper
 */
public interface ExamChooseMapper extends BaseMapper<ExamChoose> {


    /**
     * 根据学生id和试卷id得到答题纪律信息
     * @param studentId
     * @param examPaperId
     * @return
     */
    public List<ExamChooseVO> findChooseByStudentIdAndExamPaperId(@Param("studentId") Integer studentId, @Param("examPaperId") Integer examPaperId);

    /**
     * 根据学生id，试卷id，试题id获取答题记录
     * @param studentId
     * @param examPaperId
     * @param subjectId
     * @return
     */
    default ExamChoose findChooseByStudentIdAndExamPaperIdAndSubjectId(Integer studentId, Integer examPaperId, Integer subjectId) {
        Wrapper<ExamChoose> queryWrapper =
                Wrappers.lambdaQuery(ExamChoose.class).eq(ExamChoose::getStudentId, studentId).eq(ExamChoose::getExamPaperId, examPaperId).eq(ExamChoose::getSubjectId, subjectId);
        return selectOne(queryWrapper);
    }

    /**
     * 根据试卷id删除
     * @param examPaperId
     * @return
     */
    default Integer deleteByExamPaperId(Integer examPaperId) {
        Wrapper<ExamChoose> updateWrapper = Wrappers.lambdaUpdate(ExamChoose.class).eq(ExamChoose::getExamPaperId, examPaperId);
        return delete(updateWrapper);
    }

    /**
     * 根据试题获取个数
     * @param subjectId
     * @return
     */
    default Long findCountBySubjectId(Integer subjectId) {
        Wrapper<ExamChoose> queryWrapper = Wrappers.lambdaQuery(ExamChoose.class).eq(ExamChoose::getSubjectId, subjectId);
        return selectCount(queryWrapper);
    }
}
